package com.jdew.thkj.wxapi;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import com.jdew.thkj.manager.AppConfig;
import com.jdew.thkj.utils.ToastUtils;
import com.tencent.mm.sdk.constants.ConstantsAPI;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler{

	private IWXAPI api;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		api = WXAPIFactory.createWXAPI(this, AppConfig.APPID, false);
		try {
			api.handleIntent(getIntent(), this);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);

		setIntent(intent);
		api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {
	}

	@Override
	public void onResp(BaseResp resp) {
		int result = 0;
		//有时候支付结果还需要发送给服务器确认支付状态
		if (resp.getType()== ConstantsAPI.COMMAND_PAY_BY_WX){
			if (resp.errCode==0){
				ToastUtils.getInstance(this).showMessage("支付成功");
			}else if (resp.errCode==-2){
				ToastUtils.getInstance(this).showMessage("取消支付");
			}else {
				ToastUtils.getInstance(this).showMessage("支付失败");
			}
//			finish();
		}
	}
}